#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <uv.h>

#define DEFAULT_PORT 7000
#define DEFAULT_BACKLOG 128

uv_loop_t *loop;
struct sockaddr_in dest;

typedef struct {
    uv_write_t req;
    uv_buf_t buf;
} write_req_t;

void on_connect(uv_connect_t *server, int status) {
    if (status < 0) {
        fprintf(stderr, "New connection error %s\n", uv_strerror(status));
        // error!
        return;
    }

    printf("Connect server OK!\n");
}

int main() {
    uv_tcp_t client;
    uv_connect_t connect;
    loop = uv_default_loop();

    uv_tcp_init(loop, &client);

    uv_ip4_addr("127.0.0.1", DEFAULT_PORT, &dest);

    uv_tcp_connect(&connect, &client, (const struct sockaddr *)&dest, on_connect);

    return uv_run(loop, UV_RUN_DEFAULT);
}
